package org.dairy.farms.model;

import org.dairy.farms.interceptor.hibernate.Auditable;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * User: gduggira
 * Date: Jun 8, 2011
 * Time: 4:37:01 PM
 */

@javax.persistence.Table(name = "LIVESTOCK")
@Entity
public class Livestock implements Auditable {

    public enum Gender {
        MALE,FEMALE,UNKNOWN;
    }
    @javax.persistence.Column(name = "ID")
    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne
    @JoinColumn(name = "FARM_ID")
    private Farm farm;

    @javax.persistence.Column(name = "NAME")
    private String name;

    @javax.persistence.Column(name = "GIVEN_ID")
    private String givenId;

    @ManyToOne(targetEntity = Livestock.class, optional = true)
    @JoinColumn(name = "MOTHER_ID", nullable = true)
    private Livestock mother;

    @ManyToOne(targetEntity = Livestock.class, optional = true)
    @JoinColumn(name = "FATHER_ID", nullable = true)
    private Livestock father;

    @OneToMany(mappedBy = "livestock",targetEntity = LivestockNotes.class,fetch = FetchType.LAZY,cascade = CascadeType.ALL)
    private Set<LivestockNotes> livestockNotes = new HashSet<LivestockNotes>();

    @OneToMany(mappedBy = "livestock",targetEntity = LivestockFileType.class,fetch = FetchType.LAZY,cascade = CascadeType.ALL)
    private Set<LivestockFileType> livestockFileTypes = new HashSet<LivestockFileType>();

    @OneToMany(mappedBy = "livestock", targetEntity = Lactation.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<Lactation> lactations = new HashSet<Lactation>();

    @OneToMany(mappedBy = "livestock", targetEntity = Feed.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<Feed> feeds = new HashSet<Feed>();

    @OneToMany(mappedBy = "livestock", targetEntity = Checkup.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<Checkup> checkups = new HashSet<Checkup>();

    /*@OneToMany(mappedBy = "livestock", targetEntity = LivestockExpense.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<LivestockExpense> expenses = new HashSet<LivestockExpense>();
    
    @OneToMany(mappedBy = "livestock", targetEntity = LivestockRevenue.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<LivestockRevenue> revenues = new HashSet<LivestockRevenue>();*/

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "LIVESTOCK_FILE_ID")
    private LivestockFileType livestockPicture;

    @javax.persistence.Column(name = "DATE_OF_BIRTH")
    private Date dateOfBirthDate;

    @javax.persistence.Column(name = "PURCHASE_DATE")
    private Date purchaseDate;

    @javax.persistence.Column(name = "WEIGHT")
    private Double weight;

    @javax.persistence.Column(name = "HEIGHT")
    private Double height;

    @javax.persistence.Column(name = "GENETICS")
    private String genetics;

    @javax.persistence.Column(name = "PURCHASE_PRICE")
    private Double purchasePrice;

    @javax.persistence.Column(name = "EXPECTED_SELLING_PRICE")
    private Double salePrice;

    @javax.persistence.Column(name = "LIST_PRICE")
    private Double listPrice;

    @Enumerated
    private Gender gender;


    @ManyToOne
    @JoinColumn(name = "LIVESTOCK_STATUS_TYPE_ID")
    private LivestockStatusType livestockStatusType;

    public Set<Feed> getFeeds() {
        return feeds;
    }

    public void setFeeds(Set<Feed> feeds) {
        this.feeds = feeds;
    }

    public String getGenetics() {
        return genetics;
    }

    public void setGenetics(String genetics) {
        this.genetics = genetics;
    }

    public LivestockStatusType getLivestockStatusType() {
        return livestockStatusType;
    }

    public void setLivestockStatusType(LivestockStatusType livestockStatusType) {
        this.livestockStatusType = livestockStatusType;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }


    public Farm getFarm() {
        return farm;
    }

    public void setFarm(Farm farm) {
        this.farm = farm;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Livestock getMother() {
        return mother;
    }

    public void setMother(Livestock mother) {
        this.mother = mother;
    }

    public Livestock getFather() {
        return father;
    }

    public void setFather(Livestock father) {
        this.father = father;
    }

    public Set<Lactation> getLactations() {
        return lactations;
    }

    public LivestockFileType getLivestockPicture() {
        return livestockPicture;
    }

    public void setLivestockPicture(LivestockFileType livestockPicture) {
        this.livestockPicture = livestockPicture;
    }

    public void setLactations(Set<Lactation> lactations) {
        this.lactations = lactations;
    }

    public Date getDateOfBirthDate() {
        return dateOfBirthDate;
    }

    public void setDateOfBirthDate(Date dateOfBirthDate) {
        this.dateOfBirthDate = dateOfBirthDate;
    }

    public Date getPurchaseDate() {
        return purchaseDate;
    }

    public void setPurchaseDate(Date purchaseDate) {
        this.purchaseDate = purchaseDate;
    }

    public Double getWeight() {
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    public Double getHeight() {
        return height;
    }

    public void setHeight(Double height) {
        this.height = height;
    }

    public Set<Checkup> getCheckups() {
        return checkups;
    }

    public void setCheckups(Set<Checkup> checkups) {
        this.checkups = checkups;
    }

    /*public Set<LivestockExpense> getExpenses() {
        return expenses;
    }

    public void setExpenses(Set<LivestockExpense> expenses) {
        this.expenses = expenses;
    }*/

    public Double getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(Double purchasePrice) {
        this.purchasePrice = purchasePrice;
    }

    public Double getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(Double salePrice) {
        this.salePrice = salePrice;
    }

    public Double getListPrice() {
        return listPrice;
    }

    public void setListPrice(Double listPrice) {
        this.listPrice = listPrice;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public String getGivenId() {
        return givenId;
    }

    public void setGivenId(String givenId) {
        this.givenId = givenId;
    }

    /*public Set<LivestockRevenue> getRevenues() {
        return revenues;
    }

    public void setRevenues(Set<LivestockRevenue> revenues) {
        this.revenues = revenues;
    }*/

    public Set<LivestockNotes> getLivestockNotes() {
        return livestockNotes;
    }

    public void setLivestockNotes(Set<LivestockNotes> livestockNotes) {
        this.livestockNotes = livestockNotes;
    }

    public Set<LivestockFileType> getLivestockFileTypes() {
        return livestockFileTypes;
    }

    public void setLivestockFileTypes(Set<LivestockFileType> livestockFileTypes) {
        this.livestockFileTypes = livestockFileTypes;
    }

    public LivestockFileType getLivestockFileType() {
        return livestockPicture;
    }

    public void setLivestockFileType(LivestockFileType livestockFileType) {
        this.livestockPicture = livestockFileType;
    }

    @Embedded
    private AuditInfo auditInfo = new AuditInfo();

    public AuditInfo getAuditInfo() {
        return auditInfo;
    }

    public void setAuditInfo(AuditInfo auditInfo) {
        this.auditInfo = auditInfo;
    }
}
